﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ParkingLot.Entitys.Enums;
using ParkingLot.Utility.DBConnection.SqlSever;
using ParkingLot.Utility.LogHelps;

namespace ParkingLot.Utility.DBConnection
{
    /// <summary>
    /// 数据库工厂
    /// </summary>
    public class DbSessionFactory
    {
        /// <summary>
        /// 数据库类型
        /// </summary>
        public static readonly string DbSessionType;

        static DbSessionFactory()
        {
            try
            {
                DbSessionType = ConfigManager.AppSettings["DbsessionType"].Value;
                LogHelps.LogHelp.AddLog(new LogEncity()
                {
                    LogType = LogType.Init,
                    Message = Warning.Instance.DbsessionFactroyInitWarn
                });
            }
            catch (Exception exception)
            {
                LogHelps.LogHelp.AddLog(new LogEncity(Warning.Instance.DbsessionFactroyInitErrorWarn, exception));
            }
        }

        public static IDBSession GetDbsession(string connectionString)
        {
            IDBSession dbSession=null;
            switch (DbSessionType)
            {
                case "SqlSever":
                    dbSession=new SqlSeverDbSession(connectionString);
                    break;
            }
            return dbSession;
        }

        public static IDBSession GetDbsession()
        {
            IDBSession dbSession = null;
            switch (DbSessionType)
            {
                case "SqlSever":
                    dbSession = new SqlSeverDbSession();
                    break;
            }
            return dbSession;
        }

    }
}
